
<h1><span class="yiyi-st" id="yiyi-13">numpy.ma.masked_values</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.masked_values.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.masked_values.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.ma.masked_values"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">numpy.ma.</code><code class="descname">masked_values</code><span class="sig-paren">(</span><em>x</em>, <em>value</em>, <em>rtol=1e-05</em>, <em>atol=1e-08</em>, <em>copy=True</em>, <em>shrink=True</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/ma/core.py#L2223-L2302"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">使用浮点平等的掩码。</span></p>
<p><span class="yiyi-st" id="yiyi-16">返回MaskedArray，其中数组<em class="xref py py-obj">x</em>中的数据大约等于<em class="xref py py-obj">值</em>，即以下条件为True</span></p>
<p><span class="yiyi-st" id="yiyi-17">（abs（x-值）</span></p>
<p><span class="yiyi-st" id="yiyi-18">如果可能，fill_value设置为<em class="xref py py-obj">value</em>，掩码设置为<code class="docutils literal"><span class="pre">nomask</span></code>。</span><span class="yiyi-st" id="yiyi-19">对于整数，请考虑使用<code class="docutils literal"><span class="pre">masked_equal</span></code>。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-20">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-21"><strong>x</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-22">数组掩码。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-23"><strong>value</strong>：float</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-24">掩蔽值。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-25"><strong>rtol</strong>：float，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-26">公差参数。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-27"><strong>atol</strong>：float，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-28">公差参数（1e-8）。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-29"><strong>copy</strong>：bool，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-30">是否返回<em class="xref py py-obj">x</em>的副本。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-31"><strong>shrink</strong>：bool，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-32">是否将满屏为False的遮罩折叠到<code class="docutils literal"><span class="pre">nomask</span></code>。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-33">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-34"><strong>result</strong>：MaskedArray</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-35">屏蔽<em class="xref py py-obj">x</em>的结果，其中约等于<em class="xref py py-obj">值</em>。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-36">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-37"><a class="reference internal" href="numpy.ma.masked_where.html#numpy.ma.masked_where" title="numpy.ma.masked_where"><code class="xref py py-obj docutils literal"><span class="pre">masked_where</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-38">满足条件的掩码。</span></dd>
<dt><span class="yiyi-st" id="yiyi-39"><a class="reference internal" href="numpy.ma.masked_equal.html#numpy.ma.masked_equal" title="numpy.ma.masked_equal"><code class="xref py py-obj docutils literal"><span class="pre">masked_equal</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-40">掩码等于给定值（整数）。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-41">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy.ma</span> <span class="k">as</span> <span class="nn">ma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mf">1.1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mf">1.1</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">masked_values</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mf">1.1</span><span class="p">)</span>
<span class="go">masked_array(data = [1.0 -- 2.0 -- 3.0],</span>
<span class="go">      mask = [False  True False  True False],</span>
<span class="go">      fill_value=1.1)</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-42">注意，如果可能，<em class="xref py py-obj">掩码</em>设置为<code class="docutils literal"><span class="pre">nomask</span></code>。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">masked_values</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">)</span>
<span class="go">masked_array(data = [ 1.   1.1  2.   1.1  3. ],</span>
<span class="go">      mask = False,</span>
<span class="go">      fill_value=1.5)</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-43">对于整数，填充值通常与<code class="docutils literal"><span class="pre">masked_equal</span></code>的结果不同。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([0, 1, 2, 3, 4])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">masked_values</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">masked_array(data = [0 1 -- 3 4],</span>
<span class="go">      mask = [False False  True False False],</span>
<span class="go">      fill_value=2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">masked_equal</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">masked_array(data = [0 1 -- 3 4],</span>
<span class="go">      mask = [False False  True False False],</span>
<span class="go">      fill_value=999999)</span>
</pre></div>
</div>
</dd></dl>
